#include "apue.h"

int main() {
    pid_t pid;
    char command[200];

    if ((pid= fork()) < 0)
        err_sys("fork error");
    else if (pid == 0) {
        printf("child pid = %d\n", getpid());
        _exit(0);
    }

    sprintf(command, "ps -p %d -o pid=,comm=,state=", pid);
    sleep(2);   // to sure child process had exit
    printf("search child process by command ps and print it state.\n");
    if (system(command) < 0)
        err_sys("system() error");

    return (0);
}
